#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //每个标签页添加一个label
    QLabel* label1=new QLabel(ui->tab);
    label1->setText("标签1");
    label1->resize(100,50);

    QLabel* label2=new QLabel(ui->tab_2);
    label2->setText("标签2");
    label2->resize(100,50);


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //创建标签页
    int count=ui->tabWidget->count();
    QWidget* w=new QWidget();
    ui->tabWidget->addTab(w,"Tab"+QString::number(count+1));

    //添加标签
    QLabel* label=new QLabel(w);
    label->setText("标签"+QString::number(count+1));

    //设置新标签页被选中
    ui->tabWidget->setCurrentIndex(count);
}

void Widget::on_pushButton_2_clicked()
{
    //获取位置,删除
    int cur=ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(cur);
}

void Widget::on_tabWidget_currentChanged(int index)
{
    qDebug()<<"当前选中的标签是:"<<index+1;
}
